﻿using UnityEngine;
using System.Collections;

public class Createbar : MonoBehaviour
{


    Transform M;

   
    //Rigidbody rig;
    void Start()
    {
        M = this.transform;
        CreateBar(5);
        CreateMoney(8);
        CreateAddSpeed(6);
        CreateProtect(4);
    
    }

    void Update()
    {
  
    }

    void CreateBar(int m)//创建一些路障。优化时路障可以设置成一层，启动触发器，边框加宽，触发时可以加分
    {
        for (int i = 0; i < m;i++ )
        {
            GameObject bar = GameObject.CreatePrimitive(PrimitiveType.Cube);
            bar.transform.parent = M;
            bar.GetComponent<MeshRenderer>().material.color = Random.ColorHSV(); 
             
            Vector2 v = Random.insideUnitCircle * 4.5f;
            bar.transform.localPosition = new Vector3(v.x, 0.5f, v.y);
            bar.transform.localScale += new Vector3(0.5f, 5, 0);
            bar.layer = LayerMask.NameToLayer("bar");
        } 
    }

    void CreateMoney(int m)//创建一些金币
    {
        for (int i = 0; i < 8; i++)
        {
            GameObject money = GameObject.CreatePrimitive(PrimitiveType.Capsule);
            money.transform.parent = M;
            money.GetComponent<MeshRenderer>().material.color = Color.yellow;

            Vector2 v = Random.insideUnitCircle * 4.5f;
            money.transform.localPosition = new Vector3(v.x, 1, v.y);
            money.transform.localScale += new Vector3(0, 0, 0);
            money.layer = LayerMask.NameToLayer("money");
            money.GetComponent<CapsuleCollider>().isTrigger = true;
        }
    }


    void CreateAddSpeed(int m)//创建一些加速道具
    {
        for (int i = 0; i < m; i++)
        {
            GameObject addSpeed = GameObject.CreatePrimitive(PrimitiveType.Sphere);
            addSpeed.transform.parent = M;
            addSpeed.GetComponent<MeshRenderer>().material.color = Color.red;

            Vector2 v = Random.insideUnitCircle * 4.5f;
            addSpeed.transform.localPosition = new Vector3(v.x, 0.5f, v.y);
            addSpeed.transform.localScale += new Vector3(0, 0, 0);
            addSpeed.layer = LayerMask.NameToLayer("addSpeed");
            addSpeed.GetComponent<SphereCollider>().isTrigger = true;
        }
    }

    void CreateProtect(int m)//创建一些护身罩
    {
        for (int i = 0; i < m; i++)
        {
            GameObject protect = GameObject.CreatePrimitive(PrimitiveType.Cylinder);
            protect.transform.parent = M;
            protect.GetComponent<MeshRenderer>().material.color = Color.blue;

            Vector2 v = Random.insideUnitCircle * 4.5f;
            protect.transform.localPosition = new Vector3(v.x, 0.5f, v.y);
            protect.transform.localScale += new Vector3(0, 0, 0);
            protect.layer = LayerMask.NameToLayer("protect");
            protect.GetComponent<CapsuleCollider>().isTrigger = true;
        }
    }
 
}
